﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using EBA.Ex;

namespace EBA.WindowsServices
{
    public static class ConfigurationEx
    {
        public static T GetAppSetting<T>(this Configuration config, string key)
        {
            return GetAppSetting<T>(config, key, default(T));
        }

        public static T GetAppSetting<T>(this Configuration config, string key, T defaultValue)
        {
            if (config != null)
            {
                var setting = config.AppSettings.Settings[key];
                if (setting != null)
                {
                    return setting.Value.ConvertTo<T>(defaultValue);
                }

            }

            return defaultValue;
        }
    }
}
